<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Абреже</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" type="text/css" href="styles.css"/>

    <link rel="stylesheet" href="Scripts/themes/base/jquery.ui.all.css">
    <script src="Scripts/jquery-1.7.2.js"></script>
    <script src="Scripts/ui/jquery.ui.core.js"></script>
    <script src="Scripts/ui/jquery.ui.widget.js"></script>
    <script src="Scripts/ui/jquery.ui.accordion.js"></script>
    <link rel="stylesheet" href="Scripts/ui/demos.css">


    <script>
        $(function() {
            $( "#accordion" ).accordion();
        });
    </script>


    <?php session_start(); ?>
    <?php

    if ($_POST['uid'] && $_POST['passwd']) {
        if (strcmp($_POST['uid'], "") && strcmp($_POST['passwd'], "")) {

            $link = mysql_connect('localhost', 'root', 'the1soop');
            mysql_select_db('lectures');
            $login = $_POST['uid'];
            $password = $_POST['passwd'];

            $_POST['uid'] = null;
            $_POST['passwd'] = null;


            $fetched_result = mysql_fetch_array(mysql_query("SELECT `user_id`, `points`, `vip_points` FROM `user` WHERE `login`='$login' AND `password`='$password'"));

            if ($fetched_result) {
                $_POST['sql_result_reg'] = $fetched_result['user_id'];

                if ($_POST['sql_result_reg']) {
                    $_SESSION['uid'] = $login;
                    $_SESSION['points'] = $fetched_result['points'];
                    $_SESSION['vip_points'] = $fetched_result['vip_points'];
                    $_SESSION['id'] = $fetched_result['user_id'];
                }
            }

            mysql_close($link);
            $_POST['sign_id_passed'] = true;
        }
    }

    ?>

    <script>
        function stratchBorders() {
            var s = (document.getElementById('main_content').offsetHeight + 29).toString() + 'px';
            document.getElementById('left_border').style.height = s;
            document.getElementById('right_border').style.height = s;
        }
    </script>
</head>
<body onload="stratchBorders()" onresize="stratchBorders()">
<div id="wrapper">
    <div class="header" style="background-image:url(images/top.jpg)">
        <div style="text-align:right; width:43%; float:left">
            <a href="index.html"><img src="images/logo.png"/></a>
        </div>
        <div style="text-align:left; margin:0 50%; width:35%;">
            <div style="width:100%; height:20px">&nbsp;</div>
            <div class="head_menu_item"><a href="subjects.php">Рубрики</a></div>
            <div class="head_menu_item"><a href="reading_places.php">Лектории&nbsp;</a></div>
            <div class="head_menu_item"><a href="courses.php">Предметы</a></div>
        </div>
    </div>
    <div class="container">
        <div class="content">

            <div class="search_bar">

                <div class="container">
                    <div class="content">
                        <div class="header" style="height:auto">
                            <div class="container">
                                <div class="content">
                                    <div class="decorate_line_search_bar"
                                         style="background-image:url(images/search_bar_top.jpg)">&nbsp;</div>
                                    <!--text-->
                                </div>
                                <!--content-->
                                <div class="decorate_corner_left_search_bar"
                                     style="background-image:url(images/search_bar_corner_top_left.jpg)">&nbsp;</div>
                                <div class="decorate_corner_right_search_bar"
                                     style="background-image:url(images/search_bar_corner_top_right.jpg)">&nbsp;</div>
                            </div>
                            <!--container-->
                        </div>
                        <!--header-->

                        <div class="container">
                            <div class="content">
                                <div class="text" style="height:25px; text-overflow: ellipsis; overflow: hidden;">
                                    <div style="height:3px">&nbsp;</div>
                                    <div style="float:left;">
                                        <form action="">
                                            <input type="text" size="40" id="name" class="input"/>
                                            <input type="submit" value="Поиск" class="button"/>
                                        </form>
                                    </div>
                                    <div style="text-align:left; margin:0 65%; width:35%;">
                                        <div style="border-left:thick#000; width:auto; margin:0 0; text-align:right;">

                                            <div class="head_menu_item">
                                                <a href="signin.php" style="font-size:16px">
                                                    <? if ($_SESSION['uid']) {
                                                        echo $_SESSION['uid'];
                                                    } else {
                                                        echo "Вход";
                                                    } ?>
                                                </a>
                                            </div>
                                            <div class="head_menu_item"><a href="registration.php"
                                                                           style="font-size:16px">Регистрация</a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!--text-->
                            </div>
                            <!--content-->
                            <div class="left" style="height:26px; background-image:url(images/search_bar_left.jpg)">
                                &nbsp;</div>
                            <div class="right" style="height:26px; background-image:url(images/search_bar_right.jpg)">
                                &nbsp;</div>
                            <div class="clear"></div>
                        </div>

                        <div class="footer" style="height:auto">
                            <div class="container">
                                <div class="content">
                                    <div class="decorate_line_search_bar"
                                         style="background-image:url(images/search_bar_bottom.jpg)">&nbsp;</div>
                                    <!--text-->
                                </div>
                                <!--content-->
                                <div class="decorate_corner_left_search_bar"
                                     style="background-image:url(images/search_bar_corner_bottom_left.jpg)">&nbsp;</div>
                                <div class="decorate_corner_right_search_bar"
                                     style="background-image:url(images/search_bar_corner_bottom_right.jpg)">&nbsp;</div
                                        >
                            </div>
                            <!--container-->
                        </div>
                        <!--footer-->
                    </div>
                    <!--content-->
                </div>
                <!--container-->

            </div>
            <!--search_bar-->

            <div class="text">
                <div class="header">
                    <div class="container">
                        <div class="content">
                            <div class="decorate_line" style="background-image:url(images/content_top.jpg)">&nbsp;</div>
                            <!--text-->
                        </div>
                        <!--content-->
                        <div class="decorate_corner_left" style="background-image:url(images/corner_up_left.jpg)">
                            &nbsp;</div>
                        <div class="decorate_corner_right" style="background-image:url(images/corner_up_right.jpg)">
                            &nbsp;</div>

                    </div>
                    <!--container-->
                </div>
                <!--header-->
                <div class="container">
                    <div class="content">
                        <div class="text" id="main_content">

                            <?php if(((!$_SESSION['uid']) && (!$_POST['sign_id_passed'])) || ((!$_SESSION['uid']) && $_POST['sign_id_passed'] && (!$_POST['sql_result_reg']))) { ?>
                            <h1>Вход<? echo " ".$_SESSION['uid']; ?></h1>
                            <h2>Для входа в систему укажите учетные данные</h2>

                            <?php if (!$_POST['sql_result_reg'] && $_POST['sign_id_passed']) {?>
                                <p style="color: red">Учетные данные не верны. Попробуйте еще раз</p>
                            <?php } ?>

                            <form name="reg" method="post" target="">
                                <table border="0" width="30%">
                                    <tr>
                                        <td align="center" colspan="2">Registration</td>
                                    </tr>
                                    <tr>
                                        <td> Login id:</td>
                                        <td><input type="text" name="uid" size="20"></td>
                                    </tr>
                                    <tr>
                                        <td> Password:</td>
                                        <td><input type="password" name="passwd" size="20"/></td>
                                    </tr>
                                    <tr>
                                        <td align="center" colspan="2"><input type="submit" value="Sign in">
                                        </td>
                                    </tr>
                                </table>
                            </form>


                          <?php } else {
                                    $_POST['sign_id_passed'] = null; ?>

                            <h1>Кабинет пользователя&ensp;<?php echo $_SESSION['uid'];?>&nbsp;<a href="exit.php">Выход</a></h1>
                            <div id="accordion">
                                <h3><a href="#">Набранные баллы</a></h3>
                                <div class="paragraph">
                                    <p><b>Points:</b>&nbsp;<? echo $_SESSION['points'];?><br/>
                                    <b>Vip-points:</b>&nbsp;<? echo $_SESSION['vip_points'];?></p>
                                </div>

                                <h3><a href="#">Текущие заказы оцифровки лекций</a></h3>
                                <div class="paragraph">
                                    <?
                                       include_once 'utils.php';
                                       $user = $_SESSION['id'];
                                       $result = request_to_database("SELECT attachment.name FROM `order` INNER JOIN `attachment` ON order.attachment_id = attachment.attachment_id WHERE order.user_id =1");
                                       ?>
                                       <ul>
                                           <?
                                           foreach ($result as $l) {
                                               echo "<li>".$l."</li>";
                                           }
                                           ?>
                                       </ul>


                                    <p><b>Points:</b>&nbsp;<? echo $_SESSION['points'];?><br/>
                                        <b>Vip-points:</b>&nbsp;<? echo $_SESSION['vip_points'];?></p>
                                </div>
                            </div>
                          <?php } ?>
                        </div>

                    </div>
                    <!--content-->
                    <div class="left" id="left_border" style="background-image:url(images/content_left.jpg)">
                        &nbsp;</div>
                    <div class="right" id="right_border" style="background-image:url(images/content_right.jpg)">
                        &nbsp;</div>
                    <div class="clear"></div>
                </div>
                <!--container-->
                <div class="footer" style="height:auto">
                    <div class="container">
                        <div class="content">
                            <div class="decorate_line" style="background-image:url(images/content_bottom.jpg)">
                                &nbsp;</div>
                            <!--text-->
                        </div>
                        <!--content-->
                        <div class="decorate_corner_left" style="background-image:url(images/corner_bottom_left.jpg)">
                            &nbsp;</div>
                        <div class="decorate_corner_right" style="background-image:url(images/corner_bottom_right.jpg)">
                            &nbsp;</div>

                    </div>
                    <!--container-->
                </div>
                <!--footer-->
            </div>
            <!--text-->
        </div>
        <!--content-->
        <div class="clear"></div>
    </div>
    <!--container-->
    <div class="footer" style="background-image:url(images/foot.jpg)"></div>
</div>
<!--warapper-->
<div style="text-indent: -9999px;">
</div>
</body>
</html>